﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 命令模式
{

    /// <summary>
    /// 命令抽象类
    /// </summary>
    public abstract class Command
    {
        // 命令应该知道 接收者是谁，所以有Receiver这个成员变量  
        protected Receiver receiver;

        public Command(Receiver receiver)
        {
            this.receiver = receiver;
        }

        // 命令执行方法  
        public abstract void Action();
    }

    //具体命令，要干什么事 
    public class ConcreteCommand : Command
    {
        public ConcreteCommand(Receiver receiver)
            : base(receiver)
        {
        }

        public override void Action()
        {
            // 调用接收的方法，因为执行命令的是学生  
            receiver.Run1000Meters();
        }
    }
}
